package com.qinggeng.project.api.controller;

import com.google.common.collect.Maps;
import com.qinggeng.common.constant.Constants;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.project.api.dto.Classify;
import com.qinggeng.project.api.dto.GGOrderList;
import com.qinggeng.project.api.security.annotation.LoginRequired;
import com.qinggeng.project.api.security.utils.ApiUtils;
import com.qinggeng.project.api.service.IGGZYService;
import com.qinggeng.project.system.domain.HistoryWithdraw;
import com.qinggeng.project.system.domain.vo.OrdersVO;
import com.qinggeng.project.system.dto.PointOrderDTO;
import com.qinggeng.project.system.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Api(tags = "果果专员")
@RestController
@RequestMapping("${apiPath}/ggzy")
public class ApiGGzyController extends BaseController {
    @Resource
    private IGGZYService gGYZService;
    @Autowired
    private ISysConfigService sysConfigService;

    @ApiOperation("果果专员订单详情列表")
    @GetMapping("/ggorderslist")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name="startTime",value = "开始时间",dataType = "Date",paramType = "query"),
            @ApiImplicitParam(name="endTime",value = "结束时间",dataType = "Date",paramType = "query"),
            @ApiImplicitParam(name="classifyId",value="商品分类ID",dataType="Long", paramType = "query",required = false),
            @ApiImplicitParam(paramType = "header", dataType = "String", name = Constants.TOKEN, value = "token标记", required = true)
    })
    @LoginRequired(role = ApiUtils.DEFAULT_ROLE_COURIER)
    @ResponseBody
    public AjaxResult GGOrdersList(Date startTime, Date endTime,Long classifyId) {
        startPage();
        Long pointId = gGYZService.selectPointIdByUserId(ApiUtils.getUserId());
        List<GGOrderList> orderList = gGYZService.getGGOrderList(startTime,endTime,pointId,classifyId);
        return AjaxResult.success(orderList);
    }

    @ApiOperation("新版本")
    @GetMapping("/ggNewOrdersList")
    @LoginRequired(role = ApiUtils.DEFAULT_ROLE_ALL)
    @ResponseBody
    public AjaxResult ggOrderslist(PointOrderDTO dto) {
        HashMap<Object, Object> data = Maps.newHashMap();
        List<OrdersVO> orderList = gGYZService.listOrderVO(dto);
        //团长收益排行h5url
        String url = (String) sysConfigService.selectConfigByKey("sys.headIncome.url");
        data.put("orderList",orderList);
        data.put("url",url);
        return AjaxResult.success(data);
    }

    @ApiOperation("果果专员退单展示列表")
    @GetMapping("/reGGOrdersList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name="startTime",value = "开始时间",dataType = "Date",paramType = "query"),
            @ApiImplicitParam(name="endTime",value = "结束时间",dataType = "Date",paramType = "query"),
            @ApiImplicitParam(name="classifyId",value="商品分类ID",dataType="Long", paramType = "query",required = false),
            @ApiImplicitParam(paramType = "header", dataType = "String", name = Constants.TOKEN, value = "token标记", required = true)
    })
    @LoginRequired(role = ApiUtils.DEFAULT_ROLE_COURIER)
    @ResponseBody
    public AjaxResult reGGOrdersList(Date startTime, Date endTime,Long classifyId) {
        startPage();
        Long pointId = gGYZService.selectPointIdByUserId(ApiUtils.getUserId());
        List<GGOrderList> reorderList = gGYZService.getReGGOrderList(startTime,endTime,pointId,classifyId);
        return AjaxResult.success(reorderList);
    }

    @ApiOperation("果果专员分类接口")
    @GetMapping("/classify")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataType = "String", name = Constants.TOKEN, value = "token标记", required = true)
    })
    @LoginRequired(role = ApiUtils.DEFAULT_ROLE_COURIER)
    @ResponseBody
    public AjaxResult classifyList() {
        List<Classify> list = gGYZService.getClassifyList();
        return AjaxResult.success(list);
    }


    @ApiOperation("果果专员订单提现列表")
    @GetMapping("/withdrawCashList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "String", name = Constants.TOKEN, value = "token标记", required = true)
    })
    @LoginRequired(role = ApiUtils.DEFAULT_ROLE_COURIER)
    @ResponseBody
    public AjaxResult withdrawCashList() {
        startPage();
        Long userId =ApiUtils.getUserId();
        List<HistoryWithdraw> orderList = gGYZService.getWithDrawCashList(userId);
        return AjaxResult.success(orderList);
    }
}
